<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram of a Rod on Rollers</title>
</head>
<body>

<canvas id="physicsDiagramCanvas" width="600" height="400" style="border:1px solid #000;"></canvas>

<script>
    const canvas = document.getElementById('physicsDiagramCanvas');
    const ctx = canvas.getContext('2d');

    // --- Helper function for drawing arrow heads ---
    function drawArrowhead(ctx, x, y, angle, size) {
        ctx.save();
        ctx.translate(x, y);
        ctx.rotate(angle);
        ctx.beginPath();
        ctx.moveTo(0, 0);
        ctx.lineTo(-size, -size / 2.5);
        ctx.moveTo(0, 0);
        ctx.lineTo(-size, size / 2.5);
        ctx.stroke();
        ctx.restore();
    }

    // --- General Style ---
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.lineWidth = 2;
    ctx.font = '20px Times, serif';
    ctx.textAlign = 'center';

    // --- Main Components ---
    // Rod
    const rod = { x: 50, y: 150, w: 500, h: 40 };
    ctx.strokeRect(rod.x, rod.y, rod.w, rod.h);

    // Rollers
    const rollerRadius = 30;
    const roller1_x = 150;
    const roller2_x = 450;
    const roller_y = rod.y + rod.h + rollerRadius;

    // Roller 1
    ctx.beginPath();
    ctx.arc(roller1_x, roller_y, rollerRadius, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.beginPath(); // Center dot
    ctx.arc(roller1_x, roller_y, 2, 0, 2 * Math.PI);
    ctx.fill();
    ctx.fillText('1', roller1_x - rollerRadius - 20, roller_y + 7);

    // Roller 2
    ctx.beginPath();
    ctx.arc(roller2_x, roller_y, rollerRadius, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.beginPath(); // Center dot
    ctx.arc(roller2_x, roller_y, 2, 0, 2 * Math.PI);
    ctx.fill();
    ctx.fillText('2', roller2_x + rollerRadius + 20, roller_y + 7);

    // --- Rotation Arrows (schematically drawn to match the image) ---
    const arrowRadius = 18;
    const arrowHeadSize = 8;

    // Arrow for Roller 1 (Counter-Clockwise)
    const startAngle1 = 0.2 * Math.PI;
    const endAngle1 = 1.2 * Math.PI;
    ctx.beginPath();
    ctx.arc(roller1_x, roller_y, arrowRadius, startAngle1, endAngle1, false);
    ctx.stroke();
    const arrow1_endX = roller1_x + arrowRadius * Math.cos(endAngle1);
    const arrow1_endY = roller_y + arrowRadius * Math.sin(endAngle1);
    drawArrowhead(ctx, arrow1_endX, arrow1_endY, 1.25 * Math.PI, arrowHeadSize);


    // Arrow for Roller 2 (Clockwise)
    const startAngle2 = 1.2 * Math.PI;
    const endAngle2 = 0.2 * Math.PI;
    ctx.beginPath();
    ctx.arc(roller2_x, roller_y, arrowRadius, startAngle2, endAngle2, true);
    ctx.stroke();
    const arrow2_endX = roller2_x + arrowRadius * Math.cos(endAngle2);
    const arrow2_endY = roller_y + arrowRadius * Math.sin(endAngle2);
    drawArrowhead(ctx, arrow2_endX, arrow2_endY, 0.75 * Math.PI, arrowHeadSize);


    // --- Center of Mass C ---
    const c_x = 330;
    const c_y = rod.y + rod.h / 2;
    ctx.beginPath();
    ctx.arc(c_x, c_y, 3, 0, 2 * Math.PI);
    ctx.fill();
    ctx.font = 'bold 22px Times, serif';
    ctx.fillText('C', c_x + 15, c_y + 8);
    ctx.font = '20px Times, serif'; // Reset font

    // --- Dimension Lines ---
    // Dimension 'x'
    const dimX_y = rod.y - 30;
    ctx.beginPath();
    ctx.moveTo(roller1_x, rod.y);
    ctx.lineTo(roller1_x, dimX_y + 5);
    ctx.moveTo(c_x, c_y - rod.h/2);
    ctx.lineTo(c_x, dimX_y + 5);
    ctx.moveTo(roller1_x, dimX_y);
    ctx.lineTo(c_x, dimX_y);
    // Ticks for 'x'
    ctx.moveTo(roller1_x, dimX_y - 5);
    ctx.lineTo(roller1_x, dimX_y + 5);
    ctx.moveTo(c_x, dimX_y - 5);
    ctx.lineTo(c_x, dimX_y + 5);
    ctx.stroke();
    ctx.fillText('x', (roller1_x + c_x) / 2, dimX_y - 8);

    // Dimension 'a'
    const dimA_y = roller_y + rollerRadius + 30;
    ctx.beginPath();
    ctx.moveTo(roller1_x, roller_y + rollerRadius);
    ctx.lineTo(roller1_x, dimA_y);
    ctx.moveTo(roller2_x, roller_y + rollerRadius);
    ctx.lineTo(roller2_x, dimA_y);
    ctx.moveTo(roller1_x, dimA_y);
    ctx.lineTo(roller2_x, dimA_y);
    ctx.stroke();
    ctx.fillText('a', (roller1_x + roller2_x) / 2, dimA_y + 22);

    // --- Figure Caption ---
    ctx.font = 'bold 20px Times, serif';
    ctx.fillText('Fig. 1.114.', canvas.width / 2, dimA_y + 60);

</script>

</body>
</html>